package com.alks.function.mapper;

import com.alks.entity.data.entity.*;
import com.alks.function.data.dto.sys.SdVendorDto;
import com.alks.function.data.request.sys.PcCuttingProcessDetailRequest;
import com.alks.function.data.request.sys.SdVendorAddRequest;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mapstruct.Mapper;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

@Mapper
public interface SdPositionMapper extends BaseMapper<SdPosition> {

    /**
     * 查询是否存在
     * @param sdPosition
     * @return
     */
    SdPosition findPosIdResponseInfo(SdPosition sdPosition);

    /**
     * 删除
     * @param posId
     */
    Integer delPosition(String posId);

    @Select("SELECT STYLE_NO STYLE,STYLE_COLOR COLOR,PHOTO_PATH FROM SD_STYLE_COLOR WHERE PHOTO_PATH IS NOT NULL")
    List<PcPhoto> getPhoto();

    @Select("SELECT DISTINCT COLOR_PHOTO FROM SD_STYLE_COLOR WHERE STYLE_NO = #{style} AND STYLE_COLOR = #{color} ")
    InputStream getPhotoStream(@Param("style") String style,@Param("color") String color);

    /**
     * 获取派工部门
     */
    @Select("select DISPATCH_DEPT from PC_CUTTING_DISPATCH_DEPT ")
    List<String> getPcCuttingDispatchDept();

    /**
     * 查询职务
     * @param companyId
     * @return
     */
    @Select("select POS_ID as posId,POS_NAME as posName from SD_POSITION where COMPANY_ID=#{companyId}")
    List<Map<String,String>> getPosition(String companyId);

    /**
     * 查询职务列表
     * @param posName
     * @param companyId
     * @return
     */
    List<SdPosition> getSdPosition(String posName,String companyId);

    /**
     * 删除关联表信息
     * @param posId
     */
    @Delete("delete from SD_PRG_PRIVILEGE where POS_ID=#{posId}")
    void delSdPrgPrivilege(String posId);

    /**
     * 查询工序资料
     * @param companyId
     * @return
     */
    @Select("select PROCESS_CODE as processCode,PROCESS_NAME as processName from PC_CUTTING_PROCESS where COMPANY_ID=#{companyId}")
    List<Map<String,String>> getProcess(String companyId);

    /**
     * 查询工序代码是否存在
     * @param companyId
     * @param processCode
     * @return
     */
    @Select("select PROCESS_CODE  from PC_CUTTING_PROCESS where COMPANY_ID=#{companyId} and PROCESS_CODE=#{processCode}")
    String getPcCuttingProcess(@Param("companyId") String companyId, @Param("processCode") String processCode);

    /**
     * 添加工序
     * @param pcCuttingProcess
     */
    void AddPcCuttingProcess(PcCuttingProcess pcCuttingProcess);

    /**
     * 修改工序
     * @param processCode
     * @param processName
     * @param companyId
     */
    @Update("update PC_CUTTING_PROCESS set PROCESS_NAME=#{processName} where COMPANY_ID=#{companyId} and PROCESS_CODE=#{processCode}")
    void UpdatePcCuttingProcess( @Param("processCode")String processCode,  @Param("processName")String processName,@Param("companyId") String companyId);

    /**
     * 工序删除
     * @param processCode
     * @param companyId
     */
    @Delete("delete from PC_CUTTING_PROCESS where COMPANY_ID=#{companyId} and PROCESS_CODE=#{processCode}")
    void DeletePcCuttingProcess( @Param("processCode")String processCode, @Param("companyId") String companyId);

    /**
     * 查询是否被引用
     * @param companyId
     * @param processCode
     */
    @Select("select count(0) from PC_CUTTING_PROCESS_DETAIL where COMPANY_ID=#{companyId} and PROCESS_CODE=#{processCode}")
    int getPcCuttingProcessDetailToProcessCode( @Param("companyId")String companyId, @Param("processCode") String processCode);

    /**
     * 查询工艺资料
     * @param companyId
     * @param processCode
     */
    @Select("select COMPANY_ID,PROCESS_CODE,SEQ_NO,PROCESS,CT from PC_CUTTING_PROCESS_DETAIL where COMPANY_ID=#{companyId} and PROCESS_CODE=#{processCode} ")
    List<PcCuttingProcessDetail> getPcCuttingProcessDetailList(@Param("companyId")String companyId, @Param("processCode") String processCode);

    /**
     * 查询序号是否已经存在
     * @param request
     * @return
     */
    @Select("select SEQ_NO from PC_CUTTING_PROCESS_DETAIL where COMPANY_ID=#{companyId} and PROCESS_CODE=#{processCode} and SEQ_NO=#{seqNo}")
    String getPcCuttingProcessDetailToSeqNo(PcCuttingProcessDetailRequest request);

    /**
     * 添加工艺资料
     * @param request
     */
    void AddPcCuttingProcessDetail(PcCuttingProcessDetailRequest request);

    /**
     * 修改工艺资料
     * @param request
     */
    void UpdatePcCuttingProcessDetail(PcCuttingProcessDetailRequest request);

    /**
     * 删除工艺资料
     * @param request
     */
    void DeletePcCuttingProcessDetail(PcCuttingProcessDetailRequest request);

    /**
     * 查询厂商代码
     * @param vendorNo
     * @param companyId
     * @return
     */
    String getVendorNo(@Param("vendorNo") String vendorNo, @Param("companyId") String companyId);

    /**
     * 新增厂商
     * @param sdVendor
     * @return
     */
    int addSdVendor(SdVendor sdVendor);

    /**
     * 查询厂商列表
     * @param request
     * @return
     */
    List<SdVendorDto> getSdVendorList(SdVendorAddRequest request);

    /**
     * 修改厂商
     * @param sdVendor
     * @return
     */
    int updateSdVendor(SdVendor sdVendor);

    /**
     * 删除厂商
     * @param vendorNo
     * @param companyId
     * @return
     */
    int delSdVendor(@Param("vendorNo") String vendorNo, @Param("companyId") String companyId);

    /**
     * 查询厂商名称
     */
    String getNameByNo(@Param("vendorNo") String vendorNo, @Param("companyId") String companyId);

    /**
     * 查询厂商简称
     * @param vendorAbbr
     * @param companyId
     * @return
     */
    String getVendorAbbr(@Param("vendorAbbr") String vendorAbbr, @Param("companyId") String companyId);
}
